/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package wallythewatermelon;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author matthewweidman
 */
public class DrawManager {
    private static int drawIndex = 0;
    private static final int levelCount = 2;
    private static int levelIndex = 0;
    
    public static DrawMenu_Main drawMM = new DrawMenu_Main();
    public static DrawMenu_Pause drawMP = new DrawMenu_Pause();
    public static final Level levelArray[] = new Level[levelCount];
    
    public static final int MENU_MAIN = 0;
    public static final int MENU_PAUSE = -1;
    public static final int LEVELS = 2;
    
    public static Image wallyMovingLeft, wallyMovingRight;
    
    //Loads the next level in the list.
    public static void loadNextLevel()
    {
        addLevel();
        
    }
    
    public static void go(Graphics surface) {
        if (drawIndex == DrawManager.MENU_MAIN) {
            drawMM.draw(surface);
            DrawMenu_Main.startbutton.setExistence(true);
        } else if (drawIndex == DrawManager.MENU_PAUSE) {
            drawMP.draw(surface);
        } else if (drawIndex == DrawManager.LEVELS) {
            levelArray[levelIndex].draw(surface);
        }
    }
    
    public static void setDrawIndex(int i) {
        if (drawIndex != i) {
            if (i != DrawManager.MENU_MAIN) {
                DrawMenu_Main.startbutton.setExistence(false);
            } else {
                DrawMenu_Main.startbutton.setExistence(true);
            }
            if (i>=DrawManager.LEVELS) {
                Level.pausebutton.setExistence(true);
            } else {
                Level.pausebutton.setExistence(false);
            }
            if (i == DrawManager.MENU_PAUSE) {
                DrawMenu_Pause.br.setExistence(true);
            } else {
                DrawMenu_Pause.br.setExistence(false);
            }
            drawIndex = i;
        }
    }
    
    public static int getDrawIndex() {
        return drawIndex;
    }
    
    public static int getLevelIndex() {
        return levelIndex;
    }
    
    public static Watermelon getWally() {
        return DrawManager.levelArray[DrawManager.getLevelIndex()].wally;
    }
    
    public static void initLevels() {
        try {
            //DrawManager.levelArray[0] = new Level1();

            wallyMovingLeft=ImageIO.read(new File("textures/flippedwally.png"));
            wallyMovingRight=ImageIO.read(new File("textures/wally.png"));
        } catch (IOException ex) {
            System.err.println("ERROR: COULD NOT READ WALLY'S DATA.");
        }
        DrawManager.levelArray[0]=new Level();
        DrawManager.levelArray[0].loadLevel("LEVEL1");
        DrawManager.levelArray[1]=new Level();
        DrawManager.levelArray[1].loadLevel("LEVEL2");
    }
    
    public static void addLevel() {
        levelIndex++;
    }
}
